package com.gotop.mapper.core.log.config;

import com.gotop.common.config.server.ServerInfo;
import com.gotop.mapper.common.service.LogService;
import com.gotop.mapper.common.service.impl.LogServiceImpl;
import com.gotop.mapper.core.log.aspect.ApiLogAspect;
import com.gotop.mapper.core.log.event.ApiLogListener;
import com.gotop.mapper.core.log.event.ErrorLogListener;
import com.gotop.mapper.core.log.event.UsualLogListener;
import com.gotop.mapper.core.log.logger.BaseLogger;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 日志工具自动配置
 *
 * @author superfish
 */
@Configuration
@AllArgsConstructor
@ConditionalOnWebApplication
public class BladeLogToolAutoConfiguration {

    @Autowired
    private final LogServiceImpl logService;
    private final ServerInfo serverInfo;

    @Bean
    public ApiLogAspect apiLogAspect() {
        return new ApiLogAspect();
    }

    @Bean
    public BaseLogger bladeLogger() {
        return new BaseLogger();
    }

    @Bean
    public ApiLogListener apiLogListener() {
        return new ApiLogListener(logService, serverInfo);
    }

    @Bean
    public ErrorLogListener errorEventListener() {
        return new ErrorLogListener(logService, serverInfo);
    }

    @Bean
    public UsualLogListener bladeEventListener() {
        return new UsualLogListener(logService, serverInfo);
    }

}
